package com.kookapi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kookapi.common.annotation.Log;
import com.kookapi.common.core.controller.BaseController;
import com.kookapi.common.core.domain.AjaxResult;
import com.kookapi.common.enums.BusinessType;
import com.kookapi.business.domain.ApiDefinition;
import com.kookapi.business.service.IApiDefinitionService;
import com.kookapi.common.utils.poi.ExcelUtil;
import com.kookapi.common.core.page.TableDataInfo;

/**
 * 接口定义管理Controller
 * 
 * @author cleftgou
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/business/apidefinition")
public class ApiDefinitionController extends BaseController
{
    @Autowired
    private IApiDefinitionService apiDefinitionService;

    /**
     * 查询接口定义管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:apidefinition:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApiDefinition apiDefinition)
    {
        startPage();
        List<ApiDefinition> list = apiDefinitionService.selectApiDefinitionList(apiDefinition);
        return getDataTable(list);
    }

    /**
     * 导出接口定义管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:apidefinition:export')")
    @Log(title = "接口定义管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiDefinition apiDefinition)
    {
        List<ApiDefinition> list = apiDefinitionService.selectApiDefinitionList(apiDefinition);
        ExcelUtil<ApiDefinition> util = new ExcelUtil<ApiDefinition>(ApiDefinition.class);
        util.exportExcel(response, list, "接口定义管理数据");
    }

    /**
     * 获取接口定义管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:apidefinition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(apiDefinitionService.selectApiDefinitionById(id));
    }

    /**
     * 新增接口定义管理
     */
    @PreAuthorize("@ss.hasPermi('business:apidefinition:add')")
    @Log(title = "接口定义管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApiDefinition apiDefinition)
    {
        return toAjax(apiDefinitionService.insertApiDefinition(apiDefinition));
    }

    /**
     * 修改接口定义管理
     */
    @PreAuthorize("@ss.hasPermi('business:apidefinition:edit')")
    @Log(title = "接口定义管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApiDefinition apiDefinition)
    {
        return toAjax(apiDefinitionService.updateApiDefinition(apiDefinition));
    }

    /**
     * 删除接口定义管理
     */
    @PreAuthorize("@ss.hasPermi('business:apidefinition:remove')")
    @Log(title = "接口定义管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(apiDefinitionService.deleteApiDefinitionByIds(ids));
    }
}
